﻿/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __37F9D32B_31F4_455b_BEDD_5E9BE1EF8F71__
#define __37F9D32B_31F4_455b_BEDD_5E9BE1EF8F71__

namespace xos_json
{

    class mgr_impl : public i_json_mgr
    {
    public:
        typedef xos::release_impl< mgr_impl > T;

    public:
        mgr_impl();
        ~mgr_impl();

    public:
        // 
        // xos_box::i_property -> i_json
        // 
        int prop_to_json( xos_box::i_property * pProperty, char * lpszJson, int nSize, int * pnLenRet );
        int prop_to_json( xos_box::i_property * pProperty, i_json ** ppv );

        // 
        // pack to string
        // 
        int pack( i_json * pv, char * lpszStr, int nLen, int * pnLenRet );
        int parse( const char * lpszStr, int nLen, i_json ** ppv );
        int create( i_json ** ppv );

    public:
        int put_back_to_pool( T * pT, bool bLock );
        int init();
        int term();

    protected:
        int prop_to_json( xos_box::i_property * pProperty, i_json * pRoot );
        int obj_to_json( const char * lpszKey, xos_box::i_variant * pVT, i_json * pRoot );

        int helper_prop_to_json( const char * lpszKey, xos_box::i_property * pProperty, i_json * pRoot );
        int helper_list_to_json( const char * lpszKey, xos_box::i_list * pList, i_json * pRoot );

    };

} // xos_json

#endif // __37F9D32B_31F4_455b_BEDD_5E9BE1EF8F71__
